<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="用户名搜索" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入用户名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="状态" prop="passFlag">
        <dict-select :options="dict.type.audit_type" v-model="queryParams.passFlag" placeholder="请选择审核状态"/>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="dataList">
      <el-table-column label="用户名" align="left" prop="userName" width="140" :show-overflow-tooltip="true"/>
      <el-table-column label="UID" align="left" prop="userRandomId" width="140" :show-overflow-tooltip="true"/>
      <el-table-column label="消费金额等级" align="center" prop="gradeName" width="140" :show-overflow-tooltip="true"/>
      <el-table-column label="联系方式" align="center" prop="phone" width="200"/>
      <el-table-column label="更新人" align="center" prop="updateBy" width="200"/>
      <el-table-column label="更新时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d} {h}:{h}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <el-switch v-model="scope.row.viewingPermission" active-color="#13ce66" inactive-color="#ff4949" :active-value="1"
                     :inactive-value="0" @change="handleStatusChange(scope.row.userId)"
          />
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <div>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="$router.push({ path: '/user/list/:id', query: { userName: scope.row.userName } })"
            >查看
            </el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listTask, pass, reject } from '@/api/live/ownerTaskAudit'
import DateRangePicker from '@/components/DateRangePicker/index.vue'
import { deepClone } from '@/utils'
import {gradeIntegral,changeLiveViewPermission} from "@/api/live/Grade";
import {coLimit} from "@/api/user/list";
import {convertTimestamp} from "@/utils/yun";

export default {
  name: 'Task',
  components: { DateRangePicker },
  dicts: ['audit_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 店铺带货任务表格数据
      dataList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      details: {},

    }
  },
  created() {
    this.getList()
  },
  methods: {
    convertTimestamp,
    /** 查询直播间用户等级 */
    getList() {
      this.loading = true;
      gradeIntegral(this.queryParams).then(response => {
        this.dataList = response.data.records;
        this.total = response.data.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams= {
        pageNum: 1,
        pageSize: 10
      };
      this.handleQuery()
    },
    /** 观看权限修改 */
    handleStatusChange(id) {
      changeLiveViewPermission(id).then(res => {
        if (res.success) {
          this.getList()
          this.$message.success(res.msg)
        } else {
          this.$message.error(res.msg)
        }
      })
    },
  }
}
</script>
<style lang="scss" scoped>

.details-row {
  line-height: 34px;
}
.product-item {
  padding-right: 10px;
}
</style>
